/*
 * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SS_CALIBRATION_H
#define SS_CALIBRATION_H

#include "ss_pdaf.h"
#include "ss_cdaf.h"

typedef struct {
    td_s32 fdGainmap;
    td_s32 fdDccOffset;

    td_s32 rawHeight;
    td_s32 rawWidth;
    td_s32 ppWidht;
    td_s32 ppHeight;
} OT_PDAFCALIB_InitParam;

typedef struct {
    td_float zoom;
    td_float aperture;
} OT_PDAFCALIB_LensParam;

typedef struct {
    td_s32 startCode;
    td_s32 endCode;
    td_s32 stepCode;
    td_s32 frameInterval;
} OT_PDAFCALIB_MotorParam;

typedef enum {
    OT_ERR_CALIBRATION_OK = 0,
    OT_ERR_CALIBRATION_NOT_INIT,
    OT_ERR_CALIBRATION_INVALID_PIPE_ID,
    OT_ERR_CALIBRATION_INVALID_INDEX,
    OT_ERR_CALIBRATION_INVALID_REGISTER,
    OT_ERR_CALIBRATION_INVALID_FD,
    OT_ERR_CALIBRATION_INVALID_PARAM,
    OT_ERR_CALIBRATION_NULL_PTR,
    OT_ERR_CALIBRATION_INVALID_DCC,
    OT_ERR_CALIBRATION_INVALID_CONFIDENCE,
    OT_ERR_CALIBRATION_CALIB_VERIFY_FAILURE,
    OT_ERR_CALIBRATION_GAINMAP_VERIFY_FAILURE,
    OT_ERR_CALIBRATION_FAILURE
} OT_CALIBRATION_ErrorCode;

td_s32 SS_PDAFCALIB_Init(const OT_PDAFCALIB_InitParam *param);

td_s32 SS_PDAFCALIB_Deinit(td_void);

td_s32 SS_PDAFCALIB_ProcGainmap(td_u32 index, ot_vi_pipe pipe, const ot_video_frame_info *input, td_u32 meshScale);

td_s32 SS_PDAFCALIB_ConfirmMiddle(const OT_CDAF_SearchParams *cdafParam, const OT_AF_FocusWindow *win);

td_s32 SS_PDAFCALIB_ProcDccOffset(td_u32 index, const OT_PDAFCALIB_MotorParam *calibMotorParam);

td_s32 SS_PDAFCALIB_ProcDccOffsetWithLensParam(td_u32 index, const OT_PDAFCALIB_MotorParam *calibMotorParam,
    const OT_PDAFCALIB_LensParam *lensParam);

td_s32 SS_PDAFCALIB_VerifyCalibdata(td_u32 index, const OT_PDAFCALIB_MotorParam *calibMotorParam, td_float threshold);

td_s32 SS_PDAFCALIB_VerifyGainmap(td_u32 index, const ot_video_frame *videoLeft, const ot_video_frame *videoRight);

td_s32 SS_PDAFCALIB_RegisterFocusMotorAlg(OT_AF_FocusMotorAlgIntf *obj);

td_s32 SS_PDAFCALIB_RegisterCDAFAlg(OT_AF_CDAFAlgIntf *obj, const OT_CDAF_InitParam *cdInitParam);

td_s32 SS_PDAFCALIB_RegisterPDAFAlg(OT_AF_PDAFAlgIntf *obj, const OT_PDAF_InitParam *pdInitParam);

td_s32 SS_PDAFCALIB_WriteGainmap(td_void);

td_s32 SS_PDAFCALIB_WriteDccOffset(td_void);

#endif
